package com.teach;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
 * <pre>
 * -
 * Author : J.L.Zhou
 * E-Mail : 2233875735@qq.com
 * Tel : 151 1104 7708
 * Date : 2021-04-13 15:27
 * Version : 1.0
 * Copyright 2021 jlzhou.top Inc. All rights reserved.
 * Warning: this content is only for internal circulation of the company.
 *          It is forbidden to divulge it or use it for other commercial purposes.
 * </pre>
 **/
public class RuntimeTest1 {
  public static void main(String[] args)throws Exception {
    Runtime runtime = Runtime.getRuntime();
//    runtime.exec("explorer");//打开win下资源管理器
//    runtime.exec("errorCommand");//错误命令:IOException: Cannot run program ...
//    runtime.exec("C:\\Users\\86151\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe");//打开chrome
    long startTime = System.currentTimeMillis();
    Process process = runtime.exec("ping 192.168.31.241");
    InputStream in = process.getInputStream();//IO
    BufferedReader reader = new BufferedReader(new InputStreamReader(in,"GBK"));
    String line = null;
    while((line = reader.readLine())!=null){
      System.out.println(line);
    }
    System.out.println("执行ping命令耗时:"+(System.currentTimeMillis()-startTime)+"ms");
  }
}
